package com.ebeitech.auction.view.setting;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.ebeitech.auction.R;
import com.ebeitech.auction.view.PublicUtil;
import com.ebeitech.auction.view.homepage.BaseActivity;
import com.ebeitech.library.constant.SPConstants;
import com.ebeitech.library.ui.CommonItemView;
import com.ebeitech.library.ui.dialog.CommonAlertDialogFragment;
import com.ebeitech.library.util.SPManager;
import com.ebeitech.library.util.StringUtil;
import com.ebeitech.library.util.ViewUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by alice on 2017/10/31.
 */
public class UserInfoActivity extends BaseActivity {

	@BindView(R.id.view_account)
	CommonItemView viewAccount;
	@BindView(R.id.view_full_name)
	CommonItemView viewFullName;

	@OnClick({R.id.btn_logout})
	void onClick(View view){
		switch (view.getId()) {
			case R.id.btn_logout: {
				onLogoutClick();
				break;
			}
		}
	}

	private Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ebei_activity_userinfo);
		ButterKnife.bind(this);
		initView();
	}

	private void initView() {
		mContext = this;
		SPManager sp = SPManager.getInstance();
		int titleResId = getResources().getColor(R.color.ebei_text_common_dark);
		int valueResId = getResources().getColor(R.color.ebei_text_common);
		viewAccount.setTitleColor(titleResId);
		viewAccount.setTextColor(valueResId);
		viewFullName.setTitleColor(titleResId);
		viewFullName.setTextColor(valueResId);
		viewAccount.setTextValue(StringUtil.getDefaultString(sp.get(SPConstants.USER_ACCOUNT, "")));
		viewFullName.setTextValue(StringUtil.getDefaultString(sp.get(SPConstants.USER_NAME, "")));
	}

	private void onLogoutClick() {
		ViewUtil.showAlertDialog(this, R.string.ebei_logout, R.string.ebei_logout_remind, new CommonAlertDialogFragment.OnBtnClickListener() {
			@Override
			public void onClick(View v, CommonAlertDialogFragment dialog) {
				ViewUtil.dismissDialog(dialog);
				PublicUtil.doLogout(mContext);
			}
		}, null);
	}

}
